package com.cn.medicalcare.service.serviceimpl;

import com.cn.medicalcare.customtool.JsonTool;
import com.cn.medicalcare.customtool.SqlSessionFactoryTool;
import com.cn.medicalcare.mapper.CompanyMapper;
import com.cn.medicalcare.pojo.AllPage;
import com.cn.medicalcare.pojo.Company;
import com.cn.medicalcare.service.CompanyService;

import java.util.Date;
import java.util.List;

public class CompanyServiceImpl implements CompanyService {

    //静态内部类单例模式
    private static class SingletonClassInstance {
        private static final CompanyServiceImpl instance = new CompanyServiceImpl();
    }

    private CompanyServiceImpl() {
    }

    public static CompanyServiceImpl getInstance() {
        return CompanyServiceImpl.SingletonClassInstance.instance;
    }


    @Override
    public boolean insetCompany(Company company) {
        company.setTopdatetime(new Date());
        return SqlSessionFactoryTool.DoMapperAndCommit(CompanyMapper.class, m -> m.insertCompany(company));
    }

    @Override
    public boolean updateCompany(Company company) {
        if (company.getIstop() == 1) {
            company.setTopdatetime(new Date());
        }
        return SqlSessionFactoryTool.DoMapperAndCommit(CompanyMapper.class, m -> m.updateCompany(company));
    }

    @Override
    public List<Company> selectCompanyInPage(AllPage<Company> allPageCompany) {
        List<Company> list = SqlSessionFactoryTool.DoMapper(CompanyMapper.class, m -> m.selectCompanyInPage(allPageCompany));
        return list;
    }

    @Override
    public int selectCompanyCount(Company company) {
        return SqlSessionFactoryTool.DoMapper(CompanyMapper.class, m -> m.selectCompanyCount(company));
    }
}
